app.controller('employees',function($scope,$http,$state){
  $scope.selectPage = function(page){
    $http.get("/employee?page="+page).success(function(response){
      $scope.items = response.content;
      $scope.number = response.number+1;
      $scope.totalPages = response.totalPages;
      $scope.totalElements = response.totalElements;
      $scope.size = response.size
    }).error(function(data){
      alert(data.message);
    })
  }
    $scope.edit = function(employeeId){
        $state.go("home.editemployee",{id:employeeId});
    }

    $scope.delete = function(id){
        $http.delete("/employee/"+id).success(function(response){
          if(response.sucflag){
            alert(response.message);
              $state.reload();
          }
        }).error(function(data){
          alert(data.message);
        })
    }
}).controller('employee',function($scope,$http,$state){
    $scope.saveEmployee = function(){
      $http.post("/employee",$scope.item).success(function(response){
        if(response.sucflag){
          $state.go("home.employees");
        }else{
          alert(response.message);
        }
      }).error(function(data){
        alert(data.message);
      })
    }
}).controller("editemployee",function($scope,$http,$stateParams){
  $http.get("/employee/"+$stateParams.id).success(function(response){
      if(response.sucflag){
        $scope.item = response.employee
      }else{
        alert(response.sucflag);
      }
  }).error(function(data){
    alert(data.message)
  });

  //重置密码
  $scope.reset = function(id){
      $http.put("/employee/reset/"+id).success(function(response){
        alert(response.message);
      }).error(function(data){
        alert(data.message);
      });
  }

  $scope.updateEmployee = function(){
    $http.put("/employee",$scope.item).success(function(response){
      alert(response.message);
    }).error(function(data){
      alert(data.message);
    })
  }
})
